<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>找回用户密码页面</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}"/>
    <style type="text/css">

        table tr td {
            padding: 10px;
        }

    </style>
</head>
<body>
<div style="padding: 20px">

    <form method="post">
        <table>
            <tr>
                <td>邮 箱：</td>
                <td colspan="2"><input type="text" id="email" name="email" placeholder="请输入您注册用时候的邮箱"
                                       class="layui-input"/></td>
            </tr>
            <tr>
                <td>验证码：</td>
                <td><input type="text" id="yzm" name="yzm" class="layui-input" style="width: 80px"/></td>
                <td>
                    <button id="yzmbtn" class="layui-btn" onclick="sendEmail();return false;">获取验证码</button>
                </td>
            </tr>
            <tr>
                <td>
                    <button class="layui-btn" onclick="submitData();return false;">提交</button>
                </td>
                <td><font id="errorInfo" color="red"></font></td>
            </tr>
        </table>

    </form>
</div>
<script th:src="@{/js/jquery.js}" type="text/javascript"></script>
<script>

    function sendEmail() {
        var email = $("#email").val();
        if (email == "") {
            $("#errorInfo").text("请输入邮件！");
            $("#email").focus();
            return false;
        }
        //修改样式为禁用
        $("#yzmbtn").addClass("layui-btn-disabled");
        $("#yzmbtn").attr({"disabled": "disabled"});
        $("#errorInfo").text("");
        $.post("/sendEmail", {email: email}, function (result) {
            if (result.success) {
                alert("验证码已发送到您的邮箱，请注意查收，假如长时间未收到遇见，请重试！");
                $("#yzm").focus();
            } else {
                $("#errorInfo").text(result.errorInfo);
                $("#yzmbtn").removeClass("layui-btn-disabled");
                $("#yzmbtn").attr("disabled", false);
            }
        }, "json");
    }

    function submitData() {
        var yzm = $("#yzm").val();
        if (yzm == "") {
            $("#errorInfo").text("请输入验证码！");
            $("#yzm").focus();
            return false;
        }
        $.post("/checkYzm", {yzm: yzm}, function (result) {
            if (result.success) {
                alert("已通过验证，密码已经重置成123456，请登录后立刻修改密码！");
                parent.reloadPage();
            } else {
                $("#errorInfo").text(result.errorInfo);
            }
        }, "json");
    }

</script>
</body>
</html>